package com.icebergteam.warfacewidget.core.monet;
import java.io.Serializable;

import com.icebergteam.warfacewidget.core.LogManager;
import com.paypal.android.MEP.PayPalResultDelegate;

public class ResultDelegate implements PayPalResultDelegate, Serializable {

	private static SimplePayPalView context;

	public static final String className = ResultDelegate.class
			.getCanonicalName();

	private static final long serialVersionUID = 10001L;

	/**
	 * Notification that the payment has been completed successfully.
	 * 
	 * @param payKey
	 *            the pay key for the payment
	 * @param paymentStatus
	 *            the status of the transaction
	 */
	public void onPaymentSucceeded(String payKey, String paymentStatus) {

		try {
			context
					.showMessageDialog(
							"WoT Widget Donate",
							String.format(
									"SUCCESS. You have successfully completed your transaction. Key: %s",
									payKey));
		} catch (Exception e) {
			LogManager.LogE(ResultDelegate.className, LogManager.getExecuteMethodName(),
					e.getLocalizedMessage());
			e.printStackTrace();
		}

	}

	/**
	 * Notification that the payment has failed.
	 * 
	 * @param paymentStatus
	 *            the status of the transaction
	 * @param correlationID
	 *            the correlationID for the transaction failure
	 * @param payKey
	 *            the pay key for the payment
	 * @param errorID
	 *            the ID of the error that occurred
	 * @param errorMessage
	 *            the error message for the error that occurred
	 */
	public void onPaymentFailed(String paymentStatus, String correlationID,
			String payKey, String errorID, String errorMessage) {

		context.showMessageDialog("WoT Widget Donate", String.format(
				"FAILURE. %s. Error ID: %s, correlation ID: %s, Pay Key: %s",
				errorMessage, errorID, correlationID, payKey));
	}

	/**
	 * Notification that the payment was canceled.
	 * 
	 * @param paymentStatus
	 *            the status of the transaction
	 */
	public void onPaymentCanceled(String paymentStatus) {
		context.showMessageDialog("WoT Widget Donate",
				"CANCELED. The transaction has been cancelled.");
	}

	public ResultDelegate(SimplePayPalView cnxt) {
		context = cnxt;
	}
}
